/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lu.med.praxiswahl.wahlumed.dao.beans;


import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import lu.med.praxiswahl.wahlumed.dao.beans.daointerface.CodeRatesIntervalDAOInt;
import lu.med.praxiswahl.wahlumed.model.beans.CodeRatesIntervalTBL;

/**
 *
 * @author pkendzo
 */

@Stateless
public class CodeRatesIntervalDAO implements CodeRatesIntervalDAOInt{
	
	@PersistenceContext(unitName = "gynaekomedic-ejbPU")
    private EntityManager em = null;
	
	public CodeRatesIntervalDAO()
	{
		
	}

	@Override
	public void delete(Long todo)
	{
		CodeRatesIntervalTBL interval = em.find(CodeRatesIntervalTBL.class, todo);
        em.remove(interval);
        em.flush();
		
	}

	@Override
	 public CodeRatesIntervalTBL getCodeRatesInterval()
	{
		try
		{
			
			CodeRatesIntervalTBL result = (CodeRatesIntervalTBL) em
					.createQuery(
							"select co from CodeRatesIntervalTBL co ").getSingleResult();
			return result;
		}
		catch (Exception e)
		{
			return null;
		}
	}

	@Override
	public void persist(CodeRatesIntervalTBL todo)
	{
        em.persist(todo);
        em.flush();
		
	}

	@Override
	public void update(CodeRatesIntervalTBL todo)
	{
        em.merge(todo);
        em.flush();
		
	}

	@Override
	public CodeRatesIntervalTBL retrieveCodeRateIntervalByID(Long id)
	{
	    
		return (CodeRatesIntervalTBL) em.find(CodeRatesIntervalTBL.class, id);
	}

}
